package com.tingyuge.thinking.spring.configuration.bean.lifecycle;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;

/**
 * 面对注解的解析
 * @author xiaodao
 * @version 1.0
 * @date 2021/7/10
 */
public class AnnotatedBeanDefinitionParsingDemo {
    public static void main(String[] args) {
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(beanFactory);
        int beforeDefinition = beanFactory.getBeanDefinitionCount();
        //注册当前类(非 @component)
        reader.register(AnnotatedBeanDefinitionParsingDemo.class);
        int  afterBeanDefinition = beanFactory.getBeanDefinitionCount();
        int beanDefinitionCount = afterBeanDefinition-beforeDefinition;
        System.out.println("已加载: BeanDefinition的数量: "+ beanDefinitionCount);
        //普通的class 作为component 注册到 spring IOC 容器后,名称为 annotatedBeanDefinitionParsingDemo
        //bean 名称的生成 BeanNameGenerator ,注解实现 annotationBeanNameGenerator
        AnnotatedBeanDefinitionParsingDemo bean = beanFactory.getBean("annotatedBeanDefinitionParsingDemo", AnnotatedBeanDefinitionParsingDemo.class);
        System.out.println(bean);

    }
}
